@(alertLog: uk.bl.monitrix.model.AlertLog)

@import tags.{alertTag, navbar, embedParam}

@main("Monitrix - Alerts") {
  @navbar("/alerts")
}{
  @defining(alertLog.getOffendingHosts) { offendingHosts =>
    <h1>@alertLog.countAll <span class="monitrix-h1-subline">Alerts from</span> @offendingHosts.size  <span class="monitrix-h1-subline">hosts</span></h1>
    
    <table class="table table-condensed">
      <thead>
        <tr>
          <th>Offending Host</th>
          <th>Alerts</th>
          <th>#</th>
        </tr>
      </thead>
      <tbody>
        @for(host <- offendingHosts) {
          @defining(alertLog.getAlertTypesForHost(host)) { alertTypes =>
            <tr>
              <td rowspan="@alertTypes.size"><a href="@routes.Hosts.getHostInfo(host)@embedParam()">
				@if(host.length > 80) { 
					@host.substring(0,80)...
				} else { 
					@host
				}
			  </a></td>
              <td>@alertTag(alertTypes.head)</td>
              <td>@alertLog.countAlertsForHost(host, alertTypes.head)</td>
            </tr>
            @for(alertType <- alertTypes.tail) {
              <tr>
                <td>@alertTag(alertType)</td>
                <td>@alertLog.countAlertsForHost(host, alertType)</td>
              </tr>
            }
          }
        }
      </tbody>
    </table>
  }
}
